<!-- 报表管理--消耗总览 -->
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="所属风场">
                <j-select-depart placeholder="请选择所属风场" v-model="queryParam.orgName" @change="change"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属项目">
              <j-search-select-tag placeholder="请选择所属项目" v-model="queryParam.productBelong" dict=",," setFieldsValue="selectValue" :dictOptions="productBelong" @change="getpb"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="物料大类">
                <j-search-select-tag placeholder="请选择物料大类" v-model="queryParam.codeType" dict=",," setFieldsValue="selectValue" :dictOptions="equipTypeCode" @change="getetc"/>
              </a-form-item>
            </a-col>
          
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料小类">
              <j-search-select-tag placeholder="请选择物料小类" v-model="queryParam.codeSubtype" dict=",,"  setFieldsValue="selectValue" :dictOptions="equipSubtypeCode"/>
            </a-form-item>
          </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="开始时间">
                <j-date placeholder="请选择时间" v-model="queryParam.startDate"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="结束时间">
                <j-date placeholder="请选择时间" v-model="queryParam.endtDate"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="全时间端">
                <!-- <a-radio v-model="queryParam.flag"></a-radio> -->
                <a-checkbox @change="onChange" v-model="queryParam.flag"></a-checkbox>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="所属风机">
                <j-search-select-tag placeholder="请选择所属风机" v-model="queryParam.subordinateFan" dict=",," setFieldsValue="selectValue" :dictOptions="dictOptions"/>
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="出库原因">
                <a-input placeholder="请输入出库原因" v-model="queryParam.productPutReason"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button type="primary" icon="download" @click="handleExportXls('报表管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <!-- <a-button type="primary" icon="import">导入</a-button> -->
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <!-- <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button> -->
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <!-- <a style="margin-left: 24px" @click="onClearSelected">清空</a> -->
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="index"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <dt-report-modal ref="modalForm" @ok="modalFormOk"></dt-report-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import DtReportModal from './modules/DtReportModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
  import { httpAction, getAction,postAction } from '@/api/manage'
  import store from '@/store'

  export default {
    name: 'DtReportList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      JDate,
      JSelectDepart,
      JSearchSelectTag,
      DtReportModal
    },
    data () {
      return {
        departIds:'',
        orgname:'',
        equipTypeCode:[],
        equipSubtypeCode:[],
        description: '报表管理管理页面',
        productBelong:[],
        selectValue:"",
      dictOptions:[],
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
           {
            title:'所属风场',
            align:"center",
            dataIndex: 'orgName_dictText'
          },
          {
            title:'所属项目',
            align:"center",
            dataIndex: 'productBelongValue'
          },
          {
            title:'物料小类',
            align:"center",
            dataIndex: 'codeSubtypeName'
          },
          {
            title:'物料大类',
            align:"center",
            dataIndex: 'codeTypeName'
          },
          {
            title:'物料名称',
            align:"center",
            dataIndex: 'productNameValue'
          },
          {
            title:'规格型号',
            align:"center",
            dataIndex: 'productTypeName'
          },
          {
            title:'设备厂家',
            align:"center",
            dataIndex: 'factoryNameValue'
          },
          {
            title:'消耗数量',
            align:"center",
            dataIndex: 'productPutOutAmount'
          },
          {
            title:'单价',
            align:"center",
            dataIndex: 'unitPrice'
          },
          {
            title:'总价',
            align:"center",
            dataIndex: 'unitPriceTotal'
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'unitValue'
          },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/dt_product_put_storage/dtProductPutStorage/consumelist",
          delete: "/dtreport/dtReport/delete",
          deleteBatch: "/dtreport/dtReport/deleteBatch",
          exportXlsUrl: "/dtreport/dtReport/exportXls",
          importExcelUrl: "dtreport/dtReport/importExcel",
          getequipTypeCode1:"/dtproduct/dtCProduct/queryProductByParam",
           scanE:'/dt_product_put_storage/dtProductPutStorage/scanE'
          
        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      onChange(e) {
      console.log(`checked = ${e.target.checked}`);
    },
      initDictConfig(){
      },
       //选择部门之后再
      change(value){   
        console.log('value',value)
        this.departIds = value

       if(value == ''){
         console.log('没有')
          var obj = {};
          var objlist = [];
          objlist.push(obj);
         this.productBelong = objlist;
         this.equipTypeCode = objlist;
          this.productName = objlist;
          this.productType = objlist;
          this.factoryName = objlist;
       }else{
         this.getproductBelong()
       }
      },
      //所属项目选择
      getpb(value){
       console.log('value111111',value)
       if(value == undefined){
         console.log('没选')
          var obj = {};
          var objlist = [];
          objlist.push(obj);
          this.equipTypeCode = objlist;
          this.productName = objlist;
          this.productType = objlist;
          this.factoryName = objlist;
       }else{
         this.pb = value;
        this.getequipTypeCode()
        this.getproductName()
        this.productType1()
        this.getfactoryName1()
       }
        
      },
      //物料大类选择
      getetc(value){
        if(value == undefined){
          var obj = {};
          var objlist = [];
          objlist.push(obj);
          this.equipSubtypeCode = objlist

        }else{
           this.etc = value
          this.getequipSubtypeCode()
        }
       
      },

       //物料大类
      getequipTypeCode(){
        this.equipTypeCode = []
       var params = {};
        params.codeType = 'code100000';
        params.codeSortId = '100000';
       //params.content1 = '999999999';
        params.content5 = '2';
        params.productBelong = this.pb;
        params. orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.equipTypeCode = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      },
      //物料小类
      getequipSubtypeCode(){
        this.equipSubtypeCode.length=0;
        var params = {};
        var objlist = [];
        params.codeType = 'code200000';
        params.codeSortId = '200000';
       //params.content1 = '999999999';
        params.content5 = this.etc;
        params.productBelong = this.pb;
        params. orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            console.log("res=",res)
            console.log("res.result==<<<<<",res.result)
              if (res.success) {
                  if(res.result.length == 0){
                    this.equipSubtypeCode.length=0;
                    var obj = {};
                      objlist.push(obj);
                      this.equipSubtypeCode = objlist;
                  }else{
                    for(var i=0;i<res.result.length;i++){
                      var obj = {};
                      obj.value = res.result[i].dtPCode;
                      obj.text = res.result[i].dtPValue;
                      obj.title = res.result[i].dtPValue;
                      objlist.push(obj);
                    }
                    console.log(objlist)
                    this.equipSubtypeCode = objlist;
                }
              }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })
          
      },
      //物料名称
      getproductName(){
         this.equipTypeCode = []
       var params = {};
        params.codeType = 'code500000';
        params.codeSortId = '500000';
       //params.content1 = '999999999';
        params.productBelong = this.pb;
        params.orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.productName = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      },
      //设备厂家
      getfactoryName1(){
          this.equipTypeCode = []
       var params = {};
        params.codeType = 'code300000';
        params.codeSortId = '300000';
       //params.content1 = '999999999';
        params.productBelong = this.pb;
        params.orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.factoryName = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      },
      //规格型号
      productType1(){
         this.equipTypeCode = []
       var params = {};
        params.codeType = 'code400000';
        params.codeSortId = '400000';
       //params.content1 = '999999999';
        params.productBelong = this.pb;
        params.orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.productType = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      },
      //所属项目
      getproductBelong(){
        var params = {};
        params.codeType = 'code600000';
        params.codeSortId = '600000';
       //params.content1 = '999999999';
        params.orgName = this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.productBelong = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })
      },
      getpb1(){
          var params = {};
        params.codeType = 'code600000';
        params.codeSortId = '600000';
       //params.content1 = '999999999';
        params.orgName = store.getters.userInfo.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.productBelong = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      }
    },
    mounted(){
         this.getpb1()
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>